package jdk8.stream;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.stream.Collectors;

public class Count {
    public static void main(String[] args) {
        // 统计元素(终结方法)
        ArrayList<ReportCard> list = new ArrayList<>();
        list.add(new ReportCard("张三", 12, new BigDecimal("1.2")));
        list.add(new ReportCard("李四", 9, new BigDecimal("1.3")));

        System.out.println(list.stream().map(ReportCard::getScore).collect(Collectors.summarizingInt(v->v)).getSum());

        System.out.println(list.stream().map(ReportCard::getBonus).reduce(BigDecimal.valueOf(7.5), BigDecimal::add));

    }
}

class ReportCard {
    private String name;
    private Integer score; // 分数
    private BigDecimal bonus; // 奖金

    public ReportCard(String name, Integer score, BigDecimal bonus) {
        this.name = name;
        this.score = score;
        this.bonus = bonus;
    }

    public String getName() {
        return name;
    }

    public Integer getScore() {
        return score;
    }

    public BigDecimal getBonus() {
        return bonus;
    }
}
